//
//  SummaryViewController.m
//  PASystem
//
//  Created by 刘沿 on 16/8/26.
//  Copyright © 2016年 czd. All rights reserved.
//

#import "SummaryViewController.h"

@interface SummaryViewController ()
@property (nonatomic,strong) NSMutableArray *dataArray;

@property (nonatomic,strong) UIView *bgv;

@property (nonatomic,strong) UILabel *label;
@end

@implementation SummaryViewController
-(NSMutableArray *)dataArray{
    if (_dataArray == nil) {
        
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor colorWithRed:241/255.0 green:242/255.0 blue:243/255.0 alpha:1];
    
    UIView *bgV = [[UIView alloc] init];
    self.bgv = bgV;
    bgV.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:bgV];
    
    [bgV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.view.mas_top).mas_offset(10);
        make.left.equalTo(self.view.mas_left).mas_offset(10);
        make.right.equalTo(self.view.mas_right).mas_offset(-10);
        make.bottom.equalTo(self.view.mas_bottom).mas_offset(-148);
    }];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(20, 5,160,30)];
    self.label = label;
    label.text = @"项目总结";
    
    label.textColor = [UIColor blueColor];
    
    label.font = [UIFont systemFontOfSize:15];
    
    [bgV addSubview:label];
    
    UIView *vi = [[UIView alloc] initWithFrame:CGRectMake(10, 15, 4, 10)];
    vi.backgroundColor = [UIColor blueColor];
    
    [bgV addSubview:vi];
    
    [self loadData];
    
}
- (void)loadData{
    
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSString * pwdId = [[NSUserDefaults standardUserDefaults]objectForKey:@"pwdId"];
    NSString * userHumber = [[NSUserDefaults standardUserDefaults]objectForKey:@"userHumber"];
    
    NSString *json  = [NSString stringWithFormat:@"{'action': xmzjMch,'service': DXMService, 'userName':'%@','password':'%@', 'vaueJson':'{userid :%@,id:%@}'}",userId,pwdId,userHumber,self.ID];
    
    NSArray * array = @[@{@"arg0":json}];
    
    [HttpTools requestWithURL:BaseURL arrays:array method:Basemethod success:^(id JSON) {
        
        NSDictionary *dict = JSON[@"reason"];
        
        NSDictionary *dict2 = dict[@"attrs"];
        
        [self loadHTML:dict2];
        
    } failure:^(NSError *error) {
        
        
    }];
    
    
}

- (void)loadHTML:(NSDictionary *)dict{
    
    UIWebView *web = [[UIWebView alloc] init];
    
    [self.bgv addSubview:web];
    
    [web mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.label.mas_bottom).mas_offset(5);
        make.left.equalTo(self.bgv.mas_left).mas_offset(10);
        make.right.equalTo(self.bgv.mas_right).mas_offset(-10);
        make.bottom.equalTo(self.bgv.mas_bottom).mas_offset(-10);
    }];
    
    NSString *str = dict[@"SITUATION"];
    
    NSString *str1 = [str stringByReplacingOccurrencesOfString:@"&lt;" withString:@"<"];
    
    NSString *str2 = [str1 stringByReplacingOccurrencesOfString:@"&gt;" withString:@">"];
    
    [web loadHTMLString:str2 baseURL:nil];
}

@end
